package com.yungu.swift.base.model.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * @author : cuixiuyin
 * @date : 2019/11/15
 */
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Desensitization {

    /**
     * 脱敏规则类型
     */
    DesensitionType type();

    /**
     * 附加值, 自定义正则表达式等
     */
    String[] attach() default "";


    enum DesensitionType {
        /**
         * 脱敏规则枚举
         */
        MOBILE("mobile", "11位手机号", "^(\\d{3})\\d{4}(\\d{4})$", "$1****$2"),
        //注意后四位的表达式，因为有的身份证最后一位是X
        ID_CARD("idCard", "16或者18身份证号", "^(\\d{4})\\d{8,10}(\\w{4})$", "$1****$2"),
        BANK_NO("bankNo", "银行卡号", "^(\\d{4})\\d*(\\d{4})$", "$1****$2"),
        NAME("name", "真实姓名", "(?<=.{1}).(?=.{0})", "*"),
        EMAIL("email", "电子邮箱", "(\\w+)\\w{5}@(\\w+)", "$1***@$2"),
        ADDRESS("address", "住址", ""),
        CUSTOM("custom", "自定义正则处理", ""),
        ;

        String type;
        String description;
        String[] regular;

        DesensitionType(String type, String description, String... regular) {
            this.type = type;
            this.description = description;
            this.regular = regular;
        }

        public String getType() {
            return type;
        }

        public String getDescription() {
            return description;
        }

        public String[] getRegular() {
            return regular;
        }
    }
}
